package wangshuai.risk.action;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;

import publics.model.News;
import publics.util.Page;

import wangshuai.risk.service.NewsService;

import com.opensymphony.xwork2.ActionSupport;

public class NewsAction  extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private NewsService newsService;

	public NewsService getNewsService() {
		return newsService;
	}
	@Resource(name="newsService")
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
		System.out.println("newsServiceImpl inject in NewsAction!");
	}
	
	private boolean success;   //此参数为必须的， extjs根据这个参数的值判断是否成功执行操作
	private Page page;   //这是分页查询用的辅助类，用此类可以解决分页查询中要返回多个参数的问题，推荐使用
	private String conditions;//查询条件（即搜索页面上文本框中输入的值），多个条件用空格分开
	private int start;   //分页查询的 要查询数据的开始号 ，和offset值相同
	private int limit;  // 每页多少个记录
	private int newsId;
	private News news;

	public String  findNewsByPage(){
		page = new Page();
		page.setStart(0);
		page.setLimit(10);
		
		page = this.getNewsService().findByPage(page);
		page.setSuccess(true);
		return SUCCESS;
	}
	
	public String findNewsById(){
		if(newsId == 0){
			System.out.println("新闻id为0，查询失败！");
			return ERROR;
		}
		try {
			news = this.getNewsService().findById(newsId);
		} catch (DataAccessException e) {
			System.out.println("没有找到要查的新闻！");
			return ERROR;
		}
		
		return SUCCESS;
	}
	
	
	
	/**
	 * @return the success
	 */
	public boolean isSuccess() {
		return success;
	}
	/**
	 * @return the page
	 */
	public Page getPage() {
		return page;
	}
	/**
	 * @return the conditions
	 */
	public String getConditions() {
		return conditions;
	}
	/**
	 * @return the start
	 */
	public int getStart() {
		return start;
	}
	/**
	 * @return the limit
	 */
	public int getLimit() {
		return limit;
	}
	/**
	 * @param success the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}
	/**
	 * @param page the page to set
	 */
	public void setPage(Page page) {
		this.page = page;
	}
	/**
	 * @param conditions the conditions to set
	 */
	public void setConditions(String conditions) {
		this.conditions = conditions;
	}
	/**
	 * @param start the start to set
	 */
	public void setStart(int start) {
		this.start = start;
	}
	/**
	 * @param limit the limit to set
	 */
	public void setLimit(int limit) {
		this.limit = limit;
	}
	/**
	 * @return the newsId
	 */
	public int getNewsId() {
		return newsId;
	}
	/**
	 * @return the news
	 */
	public News getNews() {
		return news;
	}
	/**
	 * @param newsId the newsId to set
	 */
	public void setNewsId(int newsId) {
		this.newsId = newsId;
	}
	/**
	 * @param news the news to set
	 */
	public void setNews(News news) {
		this.news = news;
	}
	
	
	

}
